home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Prog / T / TransEdit 3.05.sit / TransEdit v 3.05 / Demos / Pascal Demos / TinyEdit / TinyEdit.p next >
Encoding:
Text File  |  1994-02-23  |  2.0 KB  |  111 lines  |  [TEXT/PJMM]

  1. program TinyEdit;
  2.  
  3.     uses
  4.         TransSkel, TransEdit;
  5.  
  6.     const
  7.  
  8.         aboutAlrt = 1000;
  9.         windRsrc = 1000;
  10.  
  11. { File menu item numbers }
  12.  
  13.         newWind = 1;
  14.         openWind = 2;
  15.         closeWind = 3;
  16.         quitApp = 5;
  17.  
  18. { Edit menu item numbers }
  19.  
  20.         undo = 1;
  21.         cut = 3;
  22.         copy = 4;
  23.         paste = 5;
  24.         clear = 6;
  25.  
  26.     var
  27.  
  28.         editWind: WindowPtr;            { non-nil if edit window open }
  29.         fileMenu: MenuHandle;
  30.         editMenu: MenuHandle;
  31.  
  32.         ignore: Boolean;
  33.  
  34.  
  35.     procedure Close;
  36.     begin
  37.         if (EWindowClose(editWind)) then
  38.             editWind := nil;
  39.     end;
  40.  
  41.  
  42.     procedure DoAppleMenu (item: Integer);
  43.         var
  44.             ignore: Integer;
  45.     begin
  46.         ignore := SkelAlert(aboutAlrt, SkelDlogFilter(nil, true), skelPositionOnParentDevice);
  47.         SkelRmveDlogFilter;
  48.     end;
  49.  
  50.  
  51.     procedure DoFileMenu (item: Integer);
  52.     begin
  53.         case item of
  54.             newWind: 
  55.                 editWind := GetNewEWindow(windRsrc, WindowPtr(-1), false);
  56.             openWind: 
  57.                 editWind := GetNewEWindow(windRsrc, WindowPtr(-1), true);
  58.             closeWind: 
  59.                 SkelClose(FrontWindow);
  60.             quitApp: 
  61.                 if (ClobberEWindows) then
  62.                     SkelStopEventLoop;
  63.         end;
  64.     end;
  65.  
  66.  
  67.     procedure AdjustMenus;
  68.     begin
  69.         DisableItem(fileMenu, closeWind);        { assume no window at all }
  70.         EnableItem(editMenu, undo);
  71.  
  72.         if (FrontWindow <> nil) then
  73.             begin
  74.                 EnableItem(fileMenu, closeWind);
  75.                 if (IsEWindow(FrontWindow)) then    { the edit window's in front }
  76.                     DisableItem(editMenu, undo);
  77.             end;
  78.         if (editWind = nil) then
  79.             begin
  80.                 EnableItem(fileMenu, newWind);
  81.                 EnableItem(fileMenu, openWind);
  82.             end
  83.         else
  84.             begin
  85.                 DisableItem(fileMenu, newWind);
  86.                 DisableItem(fileMenu, openWind);
  87.             end;
  88.     end;
  89.  
  90.  
  91. begin
  92.     editWind := nil;
  93.  
  94.     SkelInit(nil);
  95.     SkelApple('About TinyEdit…', @DoAppleMenu);
  96.     fileMenu := NewMenu(1000, 'File');
  97.     AppendMenu(fileMenu, 'New/N;Open…/O;(Close/W;(-;Quit/Q');
  98.     ignore := SkelMenu(fileMenu, @DoFileMenu, nil, false, true);
  99.  
  100.     editMenu := NewMenu(1001, 'Edit');
  101.     AppendMenu(editMenu, 'Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
  102.     ignore := SkelMenu(editMenu, @EWindowEditOp, nil, false, false);
  103.  
  104.     DrawMenuBar;
  105.     SkelSetMenuHook(@AdjustMenus);
  106.  
  107.     SetEWindowProcs(nil, nil, nil, @Close);
  108.  
  109.     SkelEventLoop;
  110.     SkelCleanup;
  111. end.